home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmiSoft / Comm / tcp / JabberwockySRC.lha / Jabberwocky / src / utility.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-04-24  |  3.5 KB  |  141 lines

  1. /*  Copyright (C) 2002 Tom Parker (tom@carrott.org),
  2.                        Matthias Münch (matthias@amigaworld.de)
  3.  
  4.     This program is free software; you can redistribute it and/or modify
  5.     it under the terms of the GNU General Public License as published by
  6.     the Free Software Foundation; either version 2 of the License, or
  7.     (at your option) any later version.
  8.  
  9.     This program is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.     GNU General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU General Public License
  15.     along with this program; if not, write to the Free Software
  16.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  17.  
  18.     In addition, as a special exception, Tom Parker and Matthias Münch give
  19.     permission to link the code of this program with a TCP stack of your 
  20.     choice, any official MUI libraries or classes and any custom MUI classes
  21.     that should be necessary for the operation of this program.  This 
  22.     exception also gives you permission to distribute linked combinations 
  23.     including this software with any of the before-mentioned libraries and 
  24.     classes.  You must obey the GNU General Public License in all respects for
  25.     all of the code used other than that provided by the before-mentioned 
  26.     libraries and classes.  As part of this exception you are obliged to 
  27.     follow the license terms of the before-mentioned libraries, this license
  28.     does not compel you to follow those terms, but if you do not then you may
  29.     not link with those libraries.  If you modify this file, you may extend
  30.     this exception to your version of the file, but you are not obligated to
  31.     do so.  If you do not wish to do so, delete this exception statement from
  32.     your version.
  33. */
  34. /*
  35. ** utility functions
  36. */
  37.  
  38. #include "common.h"
  39. #include <proto/openurl.h>
  40.  
  41. struct Library *OpenURLBase;
  42.  
  43.  
  44. listitem *list_append(list **lis, void *data)
  45. {
  46.     listitem *li;
  47.  
  48.     if(!*lis)
  49.     {
  50.         *lis = malloc(sizeof(list));
  51.         if(!*lis) return(NULL);
  52.         memset(*lis, 0, sizeof(list));
  53.     }
  54.  
  55.     li = (listitem *)data;
  56.     li->next = NULL;
  57.     li->prev = (*lis)->last;
  58.     if(!(*lis)->first) (*lis)->first = li;
  59.     if((*lis)->last) (*lis)->last->next = li;
  60.     (*lis)->last = li;
  61.     (*lis)->count++;
  62.  
  63.     return li;
  64. }
  65.  
  66.  
  67. listitem *list_prepend(list **lis, void *data)
  68. {
  69.     listitem *li;
  70.  
  71.     if(!*lis)
  72.     {
  73.         *lis = malloc(sizeof(list));
  74.         if(!*lis) return(NULL);
  75.         memset(*lis, 0, sizeof(list));
  76.     }
  77.  
  78.     li = (listitem *)data;
  79.     li->next = (*lis)->first;
  80.     li->prev = NULL;
  81.     if((*lis)->first) (*lis)->first->prev = li;
  82.     (*lis)->first = li;
  83.     if(!(*lis)->last) (*lis)->last = li;
  84.     (*lis)->count++;
  85.  
  86.     return li;
  87. }
  88.  
  89.  
  90. void list_remove(list **lis, void *data)
  91. {
  92.     listitem *li = (listitem *)data;
  93.  
  94.     if((*lis)->first == li) (*lis)->first = li->next;
  95.     if((*lis)->last == li) (*lis)->last = li->prev;
  96.     if(li->prev) li->prev->next = li->next;
  97.     if(li->next) li->next->prev = li->prev;
  98.     (*lis)->count--;
  99. }
  100.  
  101.  
  102. void list_remove_all(list **lis)
  103. {
  104.     free(*lis);
  105.     *lis = NULL;
  106. }
  107.  
  108.  
  109. char *my_printf(char *fmt, ...)
  110. {
  111.     va_list ap;
  112.     char *ret;
  113.  
  114.     va_start(ap, fmt);
  115.     ret = my_vprintf(fmt, ap);
  116.     va_end(ap);
  117.  
  118.     return ret;
  119. }
  120.  
  121.  
  122. char *my_vprintf(char *fmt, va_list ap)
  123. {
  124.     static char buf[2048];
  125.  
  126.     vsprintf(buf, fmt, ap);
  127.  
  128.     return buf;
  129. }
  130.  
  131.  
  132. void open_url(char *url)
  133. {
  134.     OpenURLBase = OpenLibrary("openurl.library",1);
  135.     if(OpenURLBase)
  136.     {
  137.         URL_Open(url, TAG_DONE);
  138.         CloseLibrary(OpenURLBase);
  139.     }
  140. }
  141.